const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {VueLoaderPlugin} = require('vue-loader');
const srcLookup = (res) => {return path.resolve(__dirname, '../src/app/' + res);};
const distLookup = (res) => {return path.resolve(__dirname, '../dist/' + res);};

const copyConfig = {
	patterns: [
		{from: srcLookup('manifest.json'), to: 'manifest.json'},
		{from: srcLookup('index.html'), to: 'index.html'}
	]
};

module.exports = {
	entry: {
		background: {
			import: srcLookup('background/index.js'),
			filename: 'js/background.index.js'
		},
		contentScript: {
			import: srcLookup('content-script/index.js'),
			filename: 'js/content-script.index.js'
		}
	},
	output: {
		path: path.resolve(__dirname, '../dist'),
		clean: true
	},
	module: {
		rules: [
			{
				test: /\.vue$/,
				loader: 'vue-loader'
			},
			{
				test: /\.js$/,
				loader: 'babel-loader'
			},
			{
				test: /\.css$/,
				use: ['vue-style-loader', 'css-loader']
			}
		],
	},
	resolve: {
		alias: {
			'@asset': srcLookup('asset'),
			'@service': srcLookup('content-script/service'),
			'@component': srcLookup('content-script/component')
		},
		fallback: {
			zlib: false,
			stream:　false,
			crypto: false,
			http: false,
			https: false,
			path: false,
			os: false,
			fs: false
		}
	},
	plugins: [
		new CopyWebpackPlugin(copyConfig),
		new VueLoaderPlugin()
	]

};